package me.zhengjie.modules.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.FieldStrategy;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
* @description /
* @author 程康
* @date 2024-12-12
**/
@Data
@TableName("sys_region")
public class Region implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty(value = "主键ID")
    private Integer id;

    @ApiModelProperty(value = "父级地区ID，0表示顶级地区")
    private Integer parentId;

    @NotBlank
    @ApiModelProperty(value = "地区名称")
    private String name;

    @NotNull
    @ApiModelProperty(value = "地区级别，例如：1-大区，2-省市，3-县区")
    private Integer level;

    @NotBlank(message = "地区编码不能为空")
    @Pattern(regexp = "^[A-Za-z]{1,20}$", message = "地区编码只能包含大小写字母，长度在1-20之间")
    @ApiModelProperty(value = "地区编码，用于唯一标识")
    private String code;

    @ApiModelProperty(value = "状态：1-启用，0-禁用")
    private Boolean status;

    @ApiModelProperty(value = "创建时间")
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Timestamp createdAt;

    @ApiModelProperty(value = "更新时间")
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Timestamp updatedAt;

    @ApiModelProperty(value = "地区排序")
    private Integer regionSort;

    @ApiModelProperty(value = "子节点数目", hidden = true)
    @TableField(exist = false)
    private Integer subCount;

    @TableField(exist = false)
    private List<Region> children = new ArrayList<>();

    @TableField(exist = false)
    private Boolean hasChildren;


    public void copy(Region source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
